package com.jz.cash.client.service.impl;

import com.jz.cash.client.dao.MerchantDao;
import com.jz.cash.client.entity.Merchant;
import com.jz.cash.client.service.MerchantService;
import com.jz.cash.client.vo.MerchantVo;
import com.stip.mybatis.generator.plugin.BaseExample;
import com.stip.mybatis.generator.plugin.BaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class MerchantServiceImpl extends BaseService<Merchant, BaseExample, Long> implements MerchantService {

    @Autowired
    private MerchantDao merchantDao;

    @Override
    public MerchantVo findByUserId(Long id) {

        Merchant merchant = merchantDao.selectByUserId(id);
        MerchantVo mv = new MerchantVo();

        Optional.ofNullable(merchant).ifPresent(f -> {
            BeanUtils.copyProperties(f, mv);
        });
        return mv;
    }
}